package java.wxw;

import java.util.Scanner;

/**
 * 显示当前文件系统中的所有文件
 * @author weisuhang
 */
public class Dir extends Final{
    public static void dir(){
        int i,j,count=0;
        String sfmode,sfpaddr,str;
        Clear.clear();// 清屏
//        dirName不为空则显示所有文件
        if(!dirName.replaceAll(" +","").equals("")){
            System.out.println("C:\\\\"+dirName+">dir");
            System.out.println("FileName\tFileAddress\tFileLength\tType\tFileMode");
            j = new DirExist().dirExist(dirName);
            for (i=0;i<fileCount[j];i++){
//                满16个清屏
                if (i%16==0&&i!=0){
                    System.out.println("按任意键继续");
                    Scanner scanner = new Scanner(System.in);
                    if (scanner.hasNext()){
                        String tmp = scanner.next();
                        Clear.clear();
                    }
                    scanner.close();
                    System.out.println("FileName\tFileAddress\tFileLength\tType\tFileMode");
                }
//                整形转换为字符串型
                str = String.valueOf(userDirs[j].userFile[i].filePANo);
                sfpaddr = "file";
                sfpaddr += str;
                if(userDirs[j].userFile[i].fileMode==0){
                    sfmode = "Read Only";
                }else if(userDirs[j].userFile[i].fileMode==1){
                    sfmode = "Write Only";
                }else if(userDirs[j].userFile[i].fileMode==2){
                    sfmode = "Read And Write";
                }else {
                    sfmode = "Protect";
                }
                System.out.println(userDirs[j].userFile[i].fileName+"\t"+sfpaddr+"\t"+userDirs[j].userFile[i].fileLenghth+"\t<FILE>\t"+sfmode);
            }
            System.out.println(fileCount[j]+"file(s)");
        }else{ //dirname为空，显示的是上一层目录(主目录)的所有文件(各个用户文件夹)
            System.out.println("C:\\\\>dir");
            System.out.println("DirName\tOwnFileCount\tType");
            for (i = 0;i < userDirCount; i++){
//                满16个清屏
                if (i%16==0&&i!=0){
                    System.out.println("按任意键继续");
                    Scanner scanner = new Scanner(System.in);
                    if (scanner.hasNext()){
                        String tmp = scanner.next();
                        Clear.clear();
                    }
                    scanner.close();
                    System.out.println("FileName\tFileAddress\tFileLength\tType\tFileMode");
                }
                System.out.println(userDirs[i].userName+"\t"+fileCount[i]+"<UFD>");
                count = count + fileCount[i];
            }
            System.out.println(userDirCount+"dir(s),"+count+" file(s)");
        }

    }
}
